
import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'
import enLang from 'element-ui/lib/locale/lang/en'// 如果使用中文语言包请默认支持，无需额外引入，请删除该依赖

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import i18n from './lang' // internationalization
import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log

import * as filters from './filters' // global filters
import Pagination from '@/components/Pagination'

import 'default-passive-events' // 移除浏览器提示 Added non-passive event listener to a scroll-blocking...

import { listByDictCode } from "@/api/admin/dict-item"
import VueQuillEditor from 'vue-quill-editor'
// 引入样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */

/* if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}*/
Vue.use(VueQuillEditor)
// 全局组件挂载
Vue.component('Pagination', Pagination)
// 全局指令注册
import permission from './directive/permission'
Vue.use(permission)

// 全局方法挂载
Vue.prototype.listByDictCode = listByDictCode
import global from "@/utils/global";
Vue.use(global)

Vue.use(Element, {
  size: Cookies.get('size') || 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

function countDecimals(num) {
  // 匹配数字的小数部分
  const match = String(num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
  // 返回小数位数
  return match ? Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0)) : 0;
}

Vue.filter('formatCurrency', function(value) {
  if (!value) return '0.00';
  let multiple=100
  var value3=Math.floor(Math.abs(value))
  var value2=makePositive(value3)/multiple
  var intPart = Number(value3).toFixed(0).slice(0, -2); // 获取整数部分
  
  let zuihou=getLastTwoDigits(value3)
  if(zuihou<10){
    zuihou='.0'+zuihou
  }else{
    zuihou='.'+zuihou
  }
  var fu
  if(value>0){
    fu=''
  }else{
    fu='-'
  }
  
  var intLen = intPart.length; // 整数部分的长度
  var result = '';
  
    while (intLen > 3) {
      result = ',' + intPart.substring(intLen - 3, intLen) + result;
      intLen -= 3;
    }

  var qian=intPart.substring(0, intLen) + result
  if(qian==''){
    qian=0
  }
  let mo=fu+qian+zuihou
  // if( Number(mo).toFixed(2)<1){
  //   mo = 0+mo
  // }
  return mo
});
//获取最后2位数
function getLastTwoDigits(number) {
  return number % 100;
}
function makePositive(number) {
  return Math.abs(number);
}

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
